<template>
  <basic-container>
    <avue-crud
      :option="option"
      :search.sync="search"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      :permission="permissionList"
      :before-open="beforeOpen"
      v-model="form"
      ref="crud"
      @row-update="rowUpdate"
      @row-save="rowSave"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @sort-change="sortChange"
      @on-load="onLoad"
    >
      <template slot-scope="scope" slot="menu">
        <el-button
          icon="el-icon-view"
          size="small"
          type="text"
          @click.stop="handleView(scope.row, scope.index)"
          >详 情</el-button
        >
      </template>
    </avue-crud>
  </basic-container>
</template>
  
  <script>
import {
  getList,
  getDetail,
  save,
} from "@/api/rb-merchant/payinvoice/payinvoiceMake";
import { mapGetters } from "vuex";

export default {
  components: {},
  data() {
    return {
      form: {},
      query: {},
      search: {},
      active: 0,
      openType: "", //打开dialog弹框的类型
      roleId: null, //角色id
      userType: "3",
      props: {
        //菜单权限数据 props
        label: "title",
        value: "key",
        disabled: this.isDisabledFn,
      },
      loading: true,
      excelBox: false,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      selectionList: [],
      option: {
        height: "calc(50vh - 50px)",
        calcHeight: 30,
        tip: false,
        border: true,
        index: true,
        selection: false,
        searchMenuSpan: 6,
        labelWidth: "150",
        columnBtn: false,
        addBtn: false,
        editBtn: false,
        viewBtn: false,
        delBtn: false,
        column: [
          {
            label: "主键",
            prop: "id",
            type: "input",
            addDisplay: false,
            editDisplay: false,
            viewDisplay: false,
            hide: true,
            overHidden: true,
          },
          {
            label: "配置内容",
            prop: "name",
            type: "input",
            display: false,
            minWidth: 150,
            overHidden: true,
          },
        ],
      },
      data: [],
    };
  },
  computed: {
    ...mapGetters(["permission", "selectMer"]),
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(",");
    },
  },
  created() {},
  methods: {
    handleView(row, index) {
      this.$router.push({
        name: row.name,
        query: {
          rpiNo: this.selectMer.rpiNo,
        },
      });
    },
    rowSave(row, done, loading) {
      save({ ...row, rpiNo: this.selectMer.rpiNo }).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          done();
        },
        (error) => {
          loading();
          window.console.log(error);
        }
      );
    },
    rowUpdate(row, index, done, loading) {
      save({ ...row, rpiNo: this.selectMer.rpiNo }).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          done();
        },
        (error) => {
          loading();
          window.console.log(error);
        }
      );
    },
    beforeOpen(done, type) {
      this.openType = type;
      if (["edit"].includes(type)) {
        // getDetail(this.form.id).then((res) => {
        //   this.form = res.data.data;
        // });
      } else if (["view"].includes(type)) {
      }
      done();
    },
    /**
     * @func 菜单权限树形是否禁止
     * @desc dialog打开类型为 view 则禁止权限树
     * @param {String} openType - 打开类型
     * */
    isDisabledFn() {
      const _this = this;
      if (["view"].includes(_this.openType)) {
        return true;
      }
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      this.data = [
        {
          id: 1,
          name: "开票人信息",
          type: "make",
        },
        {
          id: 2,
          name: "销方信息",
          type: "sales",
        },
        {
          id: 3,
          name: "购方信息",
          type: "buy",
        },
        {
          id: 4,
          name: "商品信息",
          type: "goods",
        },
      ];
      this.loading = false;
      //   getList(
      //     page.currentPage,
      //     page.pageSize,
      //     Object.assign(params, this.query, {rpiNo: this.selectMer.rpiNo})
      //   ).then((res) => {
      //     const data = res.data.data;
      //     this.page.total = data.total;
      //     this.data = data.records;
      //     this.loading = false;
      //     this.selectionClear();
      //   });
    },
    sortChange(val) {
      if (val.order == "ascending") {
        //正序
        this.query.ascs = val.prop;
        this.query.descs = "";
      } else {
        //倒序
        this.query.descs = val.prop;
        this.query.ascs = "";
      }
      this.refreshChange();
    },
  },
};
</script>
  
  <style>
</style>
  